package com.erp.gather.controller;

import com.erp.gather.domain.bo.ErpSellerProductShareBo;
import com.erp.gather.domain.vo.ErpSellerProductShareVo;
import com.erp.gather.service.IErpSellerProductShareService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;

/**
 * 个人商品分享
 *
 * @author erp
 * @date 2023-11-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/seller/sellerProductShare")
public class ErpSellerProductShareController extends BaseController {

	private final IErpSellerProductShareService iErpSellerProductShareService;

	/**
	 * 查询个人商品分享列表
	 */
	@GetMapping("/list")
	public TableDataInfo<ErpSellerProductShareVo> list(ErpSellerProductShareBo bo, PageQuery pageQuery) {
		return iErpSellerProductShareService.queryPageList(bo, pageQuery);
	}

	/**
	 * 获取个人商品分享详细信息
	 *
	 * @param id 主键
	 */
	@GetMapping("/{id}")
	public R<ErpSellerProductShareVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
		return R.ok(iErpSellerProductShareService.queryById(id));
	}

	/**
	 * 新增个人商品分享
	 */
	@RepeatSubmit()
	@PostMapping()
	public R<Object> add(@Validated(AddGroup.class) @RequestBody ErpSellerProductShareBo bo) {
		return iErpSellerProductShareService.insertByBo(bo);
	}

	/**
	 * 修改个人商品分享
	 */
	@RepeatSubmit()
	@PutMapping()
	public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpSellerProductShareBo bo) {
		return toAjax(iErpSellerProductShareService.updateByBo(bo));
	}

	/**
	 * 删除个人商品分享
	 *
	 * @param ids 主键串
	 */
	@DeleteMapping("/{ids}")
	public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
		return toAjax(iErpSellerProductShareService.deleteWithValidByIds(Arrays.asList(ids), true));
	}

	/**
	 * 使用分享码
	 * 
	 * @return
	 */
	@GetMapping("/useShare")
	public R<Object> useShare(String shareCode) {
		return iErpSellerProductShareService.useShare(shareCode);
	}
}
